package com.hm.oper_monitor.ui.initpanel;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;

import com.hm.common.util.SpringUtil;
import com.hm.oper_monitor.bean.ResourcesManager;

@SuppressWarnings("serial")
public class InitPage extends JPanel {
	private ResourcesManager rm;
	private List<JLabel> viewLabels = new ArrayList<JLabel>();
	private static InitPage page;

	private InitPage() {
		rm = SpringUtil.getBean(ResourcesManager.class);
		setLayout(new GridLayout(12, 1));
		setOpaque(false);
	}

	public static InitPage getPage() {
		if (page == null) {
			synchronized (InitPage.class) {
				if (page == null) {
					page = new InitPage();
				}
			}
		}
		return page;
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		int startX = 0;
		int startY = 0;
		
		startX = (int)rm.getScreenViewProp().getTextPosX();
		startY = (int)rm.getScreenViewProp().getTextPosY();
		
		int width = 300;
		int height = 30;
		for (int i = 0; i < viewLabels.size(); i++) {
			JLabel label = viewLabels.get(i);
			Font font = new Font("TimesRoman", Font.BOLD, 18);
			label.setFont(font);
			label.setBounds(startX, startY + i * 30, width, height);
			this.add(label);
		}
	}
	
	public void addNewLabel(String text){
		this.viewLabels.add(new JLabel(text));
		this.updateUI();
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public List<JLabel> getViewLabels() {
		return viewLabels;
	}
	public void setViewLabels(List<JLabel> viewLabels) {
		this.viewLabels = viewLabels;
	}
}
